import 'package:flutter/material.dart';

class CustomButton extends StatelessWidget {
  final double borderRadius;
  final double width;
  final double height;
  final String text;
  final Color normalColor;
  final Color pressedColor;
  final VoidCallback? onPressed;
  final VoidCallback? customOnPressed;
  final bool enabled;

  const CustomButton({
    Key? key,
    this.borderRadius = 8.0,
    this.width = double.infinity,
    this.height = 50.0,
    required this.text,
    required this.normalColor,
    required this.pressedColor,
    this.onPressed,
    this.customOnPressed,
    this.enabled = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width,
      height: height,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(borderRadius),
        color: enabled ? normalColor : normalColor.withOpacity(0.5),
      ),
      child: Material(
        color: Colors.transparent,
        borderRadius: BorderRadius.circular(borderRadius),
        child: InkWell(
          onTap: () {
            if (enabled) {
              if (customOnPressed != null) {
                customOnPressed!();
              } else if (onPressed != null) {
                onPressed!();
              }
            }
          },
          borderRadius: BorderRadius.circular(borderRadius),
          splashColor: enabled ? pressedColor.withOpacity(0.5) : Colors.transparent, // 根据按钮是否可点击设置 splashColor
          highlightColor: enabled ? normalColor.withOpacity(0.5) : Colors.transparent, // 根据按钮是否可点击设置 highlightColor
          child: Center(
            child: Text(
              text,
              style: TextStyle(
                color:  Colors.white ,
                fontSize: 16.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),
      ),
    );
  }
}